package design_pattern.singleton;


/**
 * @Name : singleton.SingleTon03
 * @Description : 懒加载，线程安全，静态内部类
 * Created by cyd on 2021-02-02 13:38:41
 */
public class SingleTon07 {
    public static void main(String[] args) {
        // 测试，拿到的实例是同一个对象
        Singlton07 instance = Singlton07.getInstance();
        Singlton07 instance1 = Singlton07.getInstance();
        System.out.println(instance == instance1);
    }
}

class Singlton07 {
    // 1.私有化构造器
    private Singlton07() {
    }

    // 2.创建一个内部类，在内部类中实例化对象
    private static class SingltonInstance {
        private static final Singlton07 INSTANCE = new Singlton07();
    }

    // 3.提供一个共有的静态方法，返回这个实例对象
    public static Singlton07 getInstance() {
        return SingltonInstance.INSTANCE;
    }
}
